//
//  LBDiscoverTableViewController.m
//  01.SinaWeibo
//
//  Created by Label on 12/12/15.
//  Copyright © 2015 Label. All rights reserved.
//

#import "LBDiscoverTableViewController.h"
#import "LBSearchBar.h"

@interface LBDiscoverTableViewController ()
@property (strong, nonatomic) LBSearchBar *searchBar;
@end

@implementation LBDiscoverTableViewController

/** 视图控制器加载完成；
 */
- (void)viewDidLoad {
        [super viewDidLoad];
        // 1. 创建搜索框；
        // 1.1 方式1-显示设置无法满足要求；
        // UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 50, 30)];
        // [searchBar setScopeBarBackgroundImage:[UIImage imageNamed:@"searchbar_textfield_background"]];
        // self.navigationItem.titleView = searchBar;
        
        // 1.2 方式2-使用自定义控件(UITextField)；
        self.searchBar = [[LBSearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.width-40, 30)];
        [self.navigationItem setTitleView:self.searchBar];
        // 注意：
        // UITableViewController不能使用事件处理函数：- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event；
        // UITableViewController若要实现点击动作，需要使用UITapGestureRecognizer；
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapTableView)];
        [self.tableView addGestureRecognizer:tapGesture];
        
        
}

- (void) tapTableView {
        // 注意：
        // 键盘的释放方式1: [self.searchBar resignFirstResponder];
        // 键盘的释放方式2: [self.navigationItem.titleView resignFirstResponder];
        // 不能使用[self.view endEditing:YES]，原因在于titleView并不在self.view中；
        [self.navigationItem.titleView resignFirstResponder];
        
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return 0;
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
        [self.searchBar resignFirstResponder];
}
/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
